home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / BARMDI.PAK / TOOLBAR.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  147 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: toolbar.c
  9. //
  10. //  PURPOSE: Handles general routines for the Toolbar control
  11. //
  12. //  FUNCTIONS:
  13. //    CreateTBar    - Creates the Toolbar control for the sample.
  14. //    MsgNotify     - Handles the WM_NOTIFY message that gets sent to
  15. //                    the parent window to get ToolTip Text.
  16. //  COMMENTS:
  17. //
  18.  
  19. #include <windows.h>            // required for all Windows applications
  20. #include <windowsx.h>
  21. #include <commctrl.h>           // prototypes and defs for common controls
  22. #include "globals.h"            // prototypes specific to this application
  23. #include "toolbar.h"            // prototypes and #defines for toolbar.c
  24. #include "resource.h"
  25.  
  26. // Global Variables for toolbar control.
  27.  
  28. HWND hWndToolbar;
  29.  
  30. //  **TODO**  Change the following values to match your toolbar bitmap
  31. //
  32. // NUMIMAGES    = Number of images in toolbar.bmp.  Note that this is not
  33. //                the same as the number of elements on the toolbar.
  34. // IMAGEWIDTH   = Width of a single button image in toolbar.bmp
  35. // IMAGEHEIGHT  = Height of a single button image in toolbar.bmp
  36. // BUTTONWIDTH  = Width of a button on the toolbar (zero = default)
  37. // BUTTONHEIGHT = Height of a button on the toolbar (zero = default)
  38.  
  39. #define NUMIMAGES       9
  40. #define IMAGEWIDTH      18
  41. #define IMAGEHEIGHT     17
  42. #define BUTTONWIDTH     0
  43. #define BUTTONHEIGHT    0
  44.  
  45. //  **TODO**  Add/remove entries in the following array to define the 
  46. //            toolbar buttons (see documentation for TBBUTTON).
  47.  
  48. TBBUTTON tbButton[] =           // Array defining the toolbar buttons
  49.  
  50.     // the struct goes like this:
  51.     // bitmap index, WM_COMMAND id, state, style, reserved bytes, app data,
  52.     // string index
  53.     // Note that the reserved bytes exist only for Win32 targets
  54. {
  55.      {0, IDM_FILENEW,    TBSTATE_ENABLED,       TBSTYLE_BUTTON, {0, 0}, 0, 0},
  56.      {1, IDM_FILEOPEN,   TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  57.      {2, IDM_FILESAVE,   TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  58.      {6, IDM_FILEPRINT,  TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  59.      {0, 0,              TBSTATE_ENABLED,       TBSTYLE_SEP,    {0, 0}, 0, 0},
  60.      {3, IDM_EDITCUT,    TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  61.      {4, IDM_EDITCOPY,   TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  62.      {5, IDM_EDITPASTE,  TBSTATE_INDETERMINATE, TBSTYLE_BUTTON, {0, 0}, 0, 0},
  63.      {0, 0,              TBSTATE_ENABLED,       TBSTYLE_SEP,    {0, 0}, 0, 0},
  64.      {7, IDM_ABOUT,      TBSTATE_ENABLED,       TBSTYLE_BUTTON, {0, 0}, 0, 0}
  65. };
  66.  
  67.  
  68. //
  69. //  FUNCTION: CreateTBar(HWND)
  70. //
  71. //  PURPOSE:  Calls CreateToolBarEx()
  72. //
  73. //
  74. //  PARAMETERS:
  75. //
  76. //  hwnd - Window handle : Used for the hWndParent parameter of the control.
  77. //
  78. //  RETURN VALUE:
  79. //
  80. //  If toolbar control was created successfully Return TRUE,
  81. //  else returns FALSE.
  82. //
  83. //  COMMENTS:
  84. //
  85. //
  86.  
  87. BOOL CreateTBar(HWND hwnd)
  88. {
  89.     hWndToolbar = CreateToolbarEx(hwnd,
  90.                                   WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS,
  91.                                   IDM_TOOLBAR,
  92.                                   NUMIMAGES,
  93.                                   hInst,
  94.                                   IDB_BMP,
  95.                                   tbButton,
  96.                                   sizeof(tbButton)/sizeof(TBBUTTON),
  97.                                   BUTTONWIDTH,
  98.                                   BUTTONHEIGHT,
  99.                                   IMAGEWIDTH,
  100.                                   IMAGEHEIGHT,
  101.                                   sizeof(TBBUTTON));
  102.  
  103.     return (hWndToolbar != NULL);
  104. }
  105.  
  106.  
  107. //
  108. //  FUNCTION: MsgNotify(HWND, UINT, WPARAM, LPARAM)
  109. //
  110. //  PURPOSE:  WM_NOTIFY is sent to the parent window to get the
  111. //            tooltip text assoc'd with that toolbar button.
  112. //
  113. //  PARAMETERS:
  114. //
  115. //    hwnd      - Window handle  (Unused)
  116. //    uMessage  - Message number (Unused)
  117. //    wparam    - Extra data     (Unused)
  118. //    lparam    - TOOLTIPTEXT FAR*
  119. //
  120. //  RETURN VALUE:
  121. //    Always returns 0 - Message handled
  122. //
  123. //
  124. //  COMMENTS:
  125. //    This message fills in the lpszText field of the TOOLTIPTEXT
  126. //    structure if code == TTN_NEEDTEXT
  127. //
  128.  
  129. #pragma argsused
  130. LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  131. {
  132.     LPTOOLTIPTEXT lpToolTipText;
  133.     static char   szBuffer[64];
  134.  
  135.     lpToolTipText = (LPTOOLTIPTEXT)lparam;
  136.     if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
  137.     {
  138.         LoadString(hInst,
  139.                    lpToolTipText->hdr.idFrom,   // string ID == command ID
  140.                    szBuffer,
  141.                          sizeof(szBuffer));
  142.  
  143.         lpToolTipText->lpszText = szBuffer;
  144.     }
  145.     return 0;
  146. }
  147.